<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta name="generator" content="Hugo 0.74.1" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>使用python爬取一个省市城市列表 | caijinglong的博客</title>
    <meta property="og:title" content="使用python爬取一个省市城市列表 - caijinglong的博客">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content="2019-01-25T13:46:47&#43;08:00">
        
        
    <meta property="article:modified_time" content="2019-01-25T13:46:47&#43;08:00">
        
    <meta name="Keywords" content="golang,go语言,flutter,caijinglong,java,android,博客,项目管理,python,软件架构,公众号,小程序">
    <meta name="description" content="使用python爬取一个省市城市列表">
        
    <meta name="author" content="caijinglong">
    <meta property="og:url" content="http://www.kikt.top/posts/python/get_city_datas/">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" href="/css/normalize.css">
    
        <link rel="stylesheet" href="/css/prism.css">
    
    <link rel="stylesheet" href="/css/style.css">
    <script type="text/javascript" src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>

    

   
    <script>
        (function(){
            var bp = document.createElement('script');
            var curProtocol = window.location.protocol.split(':')[0];
            if (curProtocol === 'https') {
                bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
            }
            else {
                bp.src = 'http://push.zhanzhang.baidu.com/push.js';
            }
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(bp, s);
        })();
    </script>

    
    
</head>

<body>
<header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="http://www.kikt.top">
                        caijinglong的博客
                    </a>
                
                <p class="description">Android/Flutter开发者，对于golang/python/ios/java 均有所了解</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="" href="http://www.kikt.top">首页</a>
                    
                    <a  href="http://www.kikt.top/archives/" title="归档">归档</a>
                    
                    <a  href="http://www.kikt.top/contact/" title="接单">接单</a>
                    
                    <a  href="http://www.kikt.top/about/" title="关于">关于</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>


<div id="body">
    <div class="container">
        <div class="col-group">

            <div class="col-8" id="main">
                <div class="res-cons">
                    <article class="post">
                        <header>
                            <h1 class="post-title">使用python爬取一个省市城市列表</h1>
                        </header>
                        <date class="post-meta meta-date">
                            2019年1月25日
                        </date>
                        
                        <div class="post-meta meta-category">
                            |
                            
                                <a href="http://www.kikt.top/categories/python">python</a>
                            
                        </div>
                        
                        
                        <div class="post-meta">
                            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span> 阅读</span></span>
                        </div>
                        
                        <div class="post-content">
                            <h2 id="前言">前言</h2>
<p>最近打算使用 <a href="https://github.com/caijinglong/flutter_city_picker" title="flutter版插件完工了,点击查看">flutter 做一个省市的级联列表</a>,但是目前没有数据来源,就想着搜搜有没有 json 的数据,结果搜了一下只有各种数据库的</p>
<p>然后搜了下有个网站说有很完整的数据的还是收费的</p>
<p>作为一个穷人程序员,如果是公司用,我付费买一个也无所谓,但是本身是想私人使用,甚至开源出去,付费就没必要了</p>
<p>这时候我想着,既然如此,我就爬一份数据,自己造一个吧</p>
<p>说到爬虫,我们就想起了<del>明年..两开花</del> python</p>
<h2 id="开发环境">开发环境</h2>
<p>使用的语言是 python3</p>
<p>request_html+基本库</p>
<h2 id="爬取网页">爬取网页</h2>
<p><a href="http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2017/">国家统计局-2017 年统计用区划代码和城乡划分代码(截止 2017 年 10 月 31 日)</a></p>
<h2 id="查看网页">查看网页</h2>
<h3 id="一级页面">一级页面</h3>
<p>使用 chrome dev 工具查看元素</p>
<p><img src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&amp;path=%2F20190125135659.png&amp;versionDescriptor%5BversionOptions%5D=0&amp;versionDescriptor%5BversionType%5D=0&amp;resolveLfs=true&amp;%24format=octetStream&amp;api-version=5.0" alt="20190125135659.png"></p>
<p>呃. table 体系,最近几年算是比较少见了</p>
<p>分析了一下,整个页面只有备案号和省份名称是 a 标签,这下过滤一下备案号,剩下的不就是我们要的数据了吗</p>
<h3 id="二级页面">二级页面</h3>
<p>点开北京,数据比较少,只有市辖区
<img src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&amp;path=%2F20190125140053.png&amp;versionDescriptor%5BversionOptions%5D=0&amp;versionDescriptor%5BversionType%5D=0&amp;resolveLfs=true&amp;%24format=octetStream&amp;api-version=5.0" alt="20190125140053.png"></p>
<p>内蒙的就比较多一点了</p>
<p><img src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&amp;path=%2F20190125140122.png&amp;versionDescriptor%5BversionOptions%5D=0&amp;versionDescriptor%5BversionType%5D=0&amp;resolveLfs=true&amp;%24format=octetStream&amp;api-version=5.0" alt="20190125140122.png"></p>
<p>纯数字的是编码,其他的是名称,也是过滤掉 IPC 备案的就好</p>
<h3 id="三级页面">三级页面</h3>
<p>和二级页面基本一致</p>
<p><img src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&amp;path=%2F20190125140255.png&amp;versionDescriptor%5BversionOptions%5D=0&amp;versionDescriptor%5BversionType%5D=0&amp;resolveLfs=true&amp;%24format=octetStream&amp;api-version=5.0" alt="20190125140255.png"></p>
<h2 id="撸码">撸码</h2>
<p>city_get.py</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#f92672">import</span> json
<span style="color:#f92672">from</span> requests_html <span style="color:#f92672">import</span> HTMLSession
<span style="color:#f92672">import</span> requests_html

session <span style="color:#f92672">=</span> HTMLSession()


<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Entity</span>:
    name: str
    link: str
    no: str
    baseUrl <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2017/&#34;</span>

    <span style="color:#66d9ef">def</span> __str__(self) <span style="color:#f92672">-&gt;</span> str:
        <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34;name:</span><span style="color:#e6db74">%s</span><span style="color:#e6db74">,link=</span><span style="color:#e6db74">%s</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span> (self<span style="color:#f92672">.</span>name, self<span style="color:#f92672">.</span>link)

    <span style="color:#66d9ef">def</span> __eq__(self, o: object) <span style="color:#f92672">-&gt;</span> bool:
        <span style="color:#66d9ef">return</span> self<span style="color:#f92672">.</span>link <span style="color:#f92672">==</span> o<span style="color:#f92672">.</span>link

    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">to_json</span>(self) <span style="color:#f92672">-&gt;</span> str:
        <span style="color:#66d9ef">pass</span>


<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">Province</span>(Entity):

    <span style="color:#66d9ef">def</span> __init__(self) <span style="color:#f92672">-&gt;</span> None:
        super()<span style="color:#f92672">.</span>__init__()
        self<span style="color:#f92672">.</span>cityList <span style="color:#f92672">=</span> []

    <span style="color:#66d9ef">def</span> __str__(self) <span style="color:#f92672">-&gt;</span> str:
        <span style="color:#66d9ef">return</span> <span style="color:#e6db74">&#34;name:</span><span style="color:#e6db74">%s</span><span style="color:#e6db74">,link=</span><span style="color:#e6db74">%s</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span> (self<span style="color:#f92672">.</span>name, self<span style="color:#f92672">.</span>link)

    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">fetch_city_list</span>(self):
        url <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">%s%s</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span> (Entity<span style="color:#f92672">.</span>baseUrl, self<span style="color:#f92672">.</span>link)
        r <span style="color:#f92672">=</span> session<span style="color:#f92672">.</span>get(url)
        r<span style="color:#f92672">.</span>encoding <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;gbk&#34;</span>
        h: requests_html<span style="color:#f92672">.</span>HTML <span style="color:#f92672">=</span> r<span style="color:#f92672">.</span>html
        li: list[requests_html<span style="color:#f92672">.</span>Element] <span style="color:#f92672">=</span> h<span style="color:#f92672">.</span>find(<span style="color:#e6db74">&#34;a&#34;</span>)
        <span style="color:#66d9ef">for</span> a <span style="color:#f92672">in</span> li:
            text <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>text
            <span style="color:#66d9ef">if</span> text<span style="color:#f92672">.</span>__contains__(<span style="color:#e6db74">&#34;京ICP&#34;</span>):
                <span style="color:#66d9ef">continue</span>
            href_ <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>attrs[<span style="color:#e6db74">&#34;href&#34;</span>]
            city <span style="color:#f92672">=</span> City()
            city<span style="color:#f92672">.</span>link <span style="color:#f92672">=</span> href_
            city<span style="color:#f92672">.</span>province <span style="color:#f92672">=</span> self
            <span style="color:#75715e"># print(text, href_)</span>

            <span style="color:#66d9ef">try</span>:
                index <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>cityList<span style="color:#f92672">.</span>index(city)
                city <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>cityList[index]
            <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">ValueError</span>:
                self<span style="color:#f92672">.</span>cityList<span style="color:#f92672">.</span>append(city)

            <span style="color:#66d9ef">if</span> text<span style="color:#f92672">.</span>isnumeric():
                city<span style="color:#f92672">.</span>no <span style="color:#f92672">=</span> text
            <span style="color:#66d9ef">else</span>:
                city<span style="color:#f92672">.</span>name <span style="color:#f92672">=</span> text

        <span style="color:#66d9ef">for</span> city <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>cityList:
            city<span style="color:#f92672">.</span>fetch_county_list()

    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">to_json</span>(self) <span style="color:#f92672">-&gt;</span> str:
        <span style="color:#66d9ef">pass</span>


<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">City</span>(Entity):
    province: Province

    <span style="color:#66d9ef">def</span> __init__(self) <span style="color:#f92672">-&gt;</span> None:
        super()<span style="color:#f92672">.</span>__init__()
        self<span style="color:#f92672">.</span>countyList <span style="color:#f92672">=</span> []

    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">fetch_county_list</span>(self):
        <span style="color:#66d9ef">print</span>(<span style="color:#e6db74">&#34;</span><span style="color:#e6db74">%s</span><span style="color:#e6db74"> 开始&#34;</span> <span style="color:#f92672">%</span> self<span style="color:#f92672">.</span>name)
        url <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">%s%s</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span> (Entity<span style="color:#f92672">.</span>baseUrl, self<span style="color:#f92672">.</span>link)
        r <span style="color:#f92672">=</span> session<span style="color:#f92672">.</span>get(url)
        r<span style="color:#f92672">.</span>encoding <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;gbk&#34;</span>
        h: requests_html<span style="color:#f92672">.</span>HTML <span style="color:#f92672">=</span> r<span style="color:#f92672">.</span>html
        li: list[requests_html<span style="color:#f92672">.</span>Element] <span style="color:#f92672">=</span> h<span style="color:#f92672">.</span>find(<span style="color:#e6db74">&#34;a&#34;</span>)
        <span style="color:#66d9ef">for</span> a <span style="color:#f92672">in</span> li:
            text <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>text
            <span style="color:#66d9ef">if</span> text<span style="color:#f92672">.</span>__contains__(<span style="color:#e6db74">&#34;京ICP&#34;</span>):
                <span style="color:#66d9ef">continue</span>
            href_ <span style="color:#f92672">=</span> a<span style="color:#f92672">.</span>attrs[<span style="color:#e6db74">&#34;href&#34;</span>]
            county <span style="color:#f92672">=</span> County()
            county<span style="color:#f92672">.</span>link <span style="color:#f92672">=</span> href_
            county<span style="color:#f92672">.</span>province <span style="color:#f92672">=</span> self
            <span style="color:#75715e"># print(text, href_)</span>

            <span style="color:#66d9ef">try</span>:
                index <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>countyList<span style="color:#f92672">.</span>index(county)
                county <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>countyList[index]
            <span style="color:#66d9ef">except</span> <span style="color:#a6e22e">ValueError</span>:
                self<span style="color:#f92672">.</span>countyList<span style="color:#f92672">.</span>append(county)

            <span style="color:#66d9ef">if</span> text<span style="color:#f92672">.</span>isnumeric():
                county<span style="color:#f92672">.</span>no <span style="color:#f92672">=</span> text
            <span style="color:#66d9ef">else</span>:
                county<span style="color:#f92672">.</span>name <span style="color:#f92672">=</span> text

        <span style="color:#66d9ef">for</span> county <span style="color:#f92672">in</span> self<span style="color:#f92672">.</span>countyList:
            <span style="color:#75715e"># print(county.__str__())</span>
            <span style="color:#66d9ef">pass</span>

        <span style="color:#66d9ef">print</span>(<span style="color:#e6db74">&#34;</span><span style="color:#e6db74">%s</span><span style="color:#e6db74"> 结束&#34;</span> <span style="color:#f92672">%</span> self<span style="color:#f92672">.</span>name)

    <span style="color:#66d9ef">pass</span>


<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">County</span>(Entity):
    city: City
    <span style="color:#66d9ef">pass</span>


provinceList <span style="color:#f92672">=</span> []


<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">fetch_province_list</span>():
    response <span style="color:#f92672">=</span> session<span style="color:#f92672">.</span>get(<span style="color:#e6db74">&#34;http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2017/index.html&#34;</span>)
    response<span style="color:#f92672">.</span>encoding <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;gbk&#34;</span>
    html: requests_html<span style="color:#f92672">.</span>HTML <span style="color:#f92672">=</span> response<span style="color:#f92672">.</span>html
    <span style="color:#75715e"># s = response.content.decode(&#34;gbk&#34;)</span>
    l: list <span style="color:#f92672">=</span> html<span style="color:#f92672">.</span>find(<span style="color:#e6db74">&#34;a&#34;</span>)
    <span style="color:#66d9ef">for</span> a <span style="color:#f92672">in</span> l:
        ae: requests_html<span style="color:#f92672">.</span>Element <span style="color:#f92672">=</span> a
        href: str <span style="color:#f92672">=</span> ae<span style="color:#f92672">.</span>attrs<span style="color:#f92672">.</span>get(<span style="color:#e6db74">&#34;href&#34;</span>)
        <span style="color:#66d9ef">if</span> href<span style="color:#f92672">.</span>endswith(<span style="color:#e6db74">&#34;html&#34;</span>):
            province <span style="color:#f92672">=</span> Province()
            province<span style="color:#f92672">.</span>name <span style="color:#f92672">=</span> ae<span style="color:#f92672">.</span>text<span style="color:#f92672">.</span>lstrip()
            province<span style="color:#f92672">.</span>link <span style="color:#f92672">=</span> href<span style="color:#f92672">.</span>lstrip()
            provinceList<span style="color:#f92672">.</span>append(province)


fetch_province_list()

<span style="color:#66d9ef">if</span> __name__ <span style="color:#f92672">==</span> <span style="color:#e6db74">&#39;__main__&#39;</span>:
    <span style="color:#66d9ef">for</span> p <span style="color:#f92672">in</span> provinceList:
        <span style="color:#66d9ef">if</span> p<span style="color:#f92672">.</span>name <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;黑龙江省&#34;</span>:
            p<span style="color:#f92672">.</span>fetch_city_list()
<span style="color:#75715e"># session.close()</span>

</code></pre></div><p>dump_data.py</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#f92672">import</span> json

<span style="color:#f92672">from</span> city.city_get <span style="color:#f92672">import</span> Province, County, City, provinceList
<span style="color:#f92672">import</span> datetime

<span style="color:#75715e"># for p in provinceList:</span>
<span style="color:#75715e">#     pr: Province = p</span>
version <span style="color:#f92672">=</span> <span style="color:#ae81ff">2</span>

di <span style="color:#f92672">=</span> dict()
di[<span style="color:#e6db74">&#34;version&#34;</span>] <span style="color:#f92672">=</span> version
now <span style="color:#f92672">=</span> datetime<span style="color:#f92672">.</span>datetime<span style="color:#f92672">.</span>now()
date <span style="color:#f92672">=</span> datetime<span style="color:#f92672">.</span>datetime<span style="color:#f92672">.</span>strftime(now, <span style="color:#e6db74">&#34;%Y-%m-</span><span style="color:#e6db74">%d</span><span style="color:#e6db74"> %H:%M:%S&#34;</span>)
di[<span style="color:#e6db74">&#34;date&#34;</span>] <span style="color:#f92672">=</span> date
di[<span style="color:#e6db74">&#34;timeStamp&#34;</span>] <span style="color:#f92672">=</span> now<span style="color:#f92672">.</span>timestamp()

proList <span style="color:#f92672">=</span> []


<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">make_province</span>(p: Province):
    p<span style="color:#f92672">.</span>fetch_city_list()
    p_dict <span style="color:#f92672">=</span> dict()
    city_list <span style="color:#f92672">=</span> []

    p_dict[<span style="color:#e6db74">&#34;name&#34;</span>] <span style="color:#f92672">=</span> p<span style="color:#f92672">.</span>name

    <span style="color:#66d9ef">for</span> city <span style="color:#f92672">in</span> p<span style="color:#f92672">.</span>cityList:
        city: City <span style="color:#f92672">=</span> city
        c_dict <span style="color:#f92672">=</span> dict()
        c_dict[<span style="color:#e6db74">&#34;name&#34;</span>] <span style="color:#f92672">=</span> city<span style="color:#f92672">.</span>name
        c_dict[<span style="color:#e6db74">&#34;no&#34;</span>] <span style="color:#f92672">=</span> city<span style="color:#f92672">.</span>no
        city_list<span style="color:#f92672">.</span>append(c_dict)
        make_city(city, c_dict)

    p_dict[<span style="color:#e6db74">&#34;cityList&#34;</span>] <span style="color:#f92672">=</span> city_list
    proList<span style="color:#f92672">.</span>append(p_dict)


<span style="color:#66d9ef">def</span> <span style="color:#a6e22e">make_city</span>(city: City, city_obj: dict):
    city<span style="color:#f92672">.</span>fetch_county_list()
    li <span style="color:#f92672">=</span> []
    county_list: list[County] <span style="color:#f92672">=</span> city<span style="color:#f92672">.</span>countyList
    <span style="color:#66d9ef">for</span> county <span style="color:#f92672">in</span> county_list:
        c_obj <span style="color:#f92672">=</span> dict()
        c_obj[<span style="color:#e6db74">&#34;name&#34;</span>] <span style="color:#f92672">=</span> county<span style="color:#f92672">.</span>name
        c_obj[<span style="color:#e6db74">&#34;no&#34;</span>] <span style="color:#f92672">=</span> county<span style="color:#f92672">.</span>no
        li<span style="color:#f92672">.</span>append(c_obj)

    city_obj[<span style="color:#e6db74">&#34;countyList&#34;</span>] <span style="color:#f92672">=</span> li
    <span style="color:#66d9ef">pass</span>


<span style="color:#66d9ef">for</span> province <span style="color:#f92672">in</span> provinceList:
    <span style="color:#66d9ef">print</span>(<span style="color:#e6db74">&#34;province = </span><span style="color:#e6db74">%s</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">%</span> province<span style="color:#f92672">.</span>name)
    make_province(province)

di[<span style="color:#e6db74">&#34;provinceList&#34;</span>] <span style="color:#f92672">=</span> proList

s <span style="color:#f92672">=</span> json<span style="color:#f92672">.</span>dumps(di)

f <span style="color:#f92672">=</span> open(<span style="color:#e6db74">&#34;data/city-version-</span><span style="color:#e6db74">%s</span><span style="color:#e6db74">.json&#34;</span> <span style="color:#f92672">%</span> version, <span style="color:#e6db74">&#39;w&#39;</span>)

f<span style="color:#f92672">.</span>write(s)

</code></pre></div><p>分了两个文件,其中一个是获取数据,一个是将数据转为 json 形式保存</p>
<p>如果后续有必要,也可以弄一个数据库,具体是 sqlite 还是 mysql 都可以自己解析 json 插入,对于一个合格的程序员都是小意思</p>
<h2 id="代码">代码</h2>
<p>代码可以从<a href="https://github.com/CaiJingLong/python_get_city_datas">github</a>仓库查看</p>
<h2 id="生成数据">生成数据</h2>
<p>生成的数据比较大,大概有 22w 字符 200 多 K</p>
<p>可以从<a href="https://github.com/CaiJingLong/python_get_city_datas/releases">github release</a>下载</p>
<p>或直接从<a href="https://github.com/CaiJingLong/python_get_city_datas/blob/f9465f7b52dcfac346db54c2eda7c759b8183d43/data/city-version-4.json">city-version-4.json</a> copy</p>
<p>格式化完的数据有 14000 行左右, 可以查看<a href="https://github.com/CaiJingLong/python_get_city_datas/blob/f9465f7b52dcfac346db54c2eda7c759b8183d43/data/city-version-4-pretty.json">pretty-json</a></p>
<p><a href="https://github.com/CaiJingLong/python_get_city_datas/blob/f9465f7b52dcfac346db54c2eda7c759b8183d43/data/city_version-4.sqlite">sqlite 版</a></p>

                        </div>

                        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/posts/flutter/android/profile-1/">在Profile下分析android内存占用</a></li>
        
        <li><a href="/posts/flutter/exists/android/">在原 Android 工程的基础上构建一个flutter工程</a></li>
        
        <li><a href="/posts/android/android-include-ffmpeg/">android 引入ffmpeg</a></li>
        
        <li><a href="/posts/android/android-ffmpeg-compile-so/">ndk编译ffmpeg</a></li>
        
        <li><a href="/posts/flutter/framework/cupertino-paste-tooltip/">flutter cupertino 复制粘贴弹窗报错的问题</a></li>
        
    </ul>
</div>


                        <div class="post-meta meta-tags">
                            
                            <ul class="clearfix">
                                
                                <li><a href="http://www.kikt.top/tags/%E7%88%AC%E8%99%AB">爬虫</a></li>
                                
                                <li><a href="http://www.kikt.top/tags/python">python</a></li>
                                
                                <li><a href="http://www.kikt.top/tags/%E5%9F%8E%E5%B8%82">城市</a></li>
                                
                            </ul>
                            
                        </div>
                    </article>
                    
    

    
    
    <div class="post bg-white">
      <script src="https://utteranc.es/client.js"
            repo= "caijinglong/kikt-blog-comment"
            issue-term="pathname"
            theme="github-light"
            crossorigin="anonymous"
            async>
      </script>
    </div>
    
                </div>
            </div>
            <div id="secondary">
    <section class="widget">
        <form id="search" action="//www.google.com/search" method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="http://www.kikt.top">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="http://www.kikt.top/posts/java/crack/crack1/" title="使用javassist,修改jar包方法实现">使用javassist,修改jar包方法实现</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/github/actions/create/" title="Github action 的开发到发布">Github action 的开发到发布</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/jenkins&#43;fastlane/" title="flutter Jenkins&#43;fastlane 自动化打测试包, 并上传蒲公英">flutter Jenkins&#43;fastlane 自动化打测试包, 并上传蒲公英</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/go/compile-for-android/" title="编译 go 源码为 android 动态库(so)">编译 go 源码为 android 动态库(so)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/focusnode-2/" title="Flutter FocusNode 焦点那点事-(二)">Flutter FocusNode 焦点那点事-(二)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/focusnode-1/" title="Flutter FocusNode 焦点那点事-(一)">Flutter FocusNode 焦点那点事-(一)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/server/caddy/cros_for_local_dev/" title="用 Caddy 解决 web 开发中本地跨域的问题">用 Caddy 解决 web 开发中本地跨域的问题</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/route/navigator-helper2/" title="Navigator Helper2">Navigator Helper2</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/grey-app/" title="flutter 怎么实现app整体灰度">flutter 怎么实现app整体灰度</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/posts/flutter/plugin/flutter-sdk-import-aar/" title="Flutter 插件开发之引入aar到安卓部分 并使用本地maven">Flutter 插件开发之引入aar到安卓部分 并使用本地maven</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title">分类</h3>
<ul class="widget-list">
    
    <li>
        <a href="http://www.kikt.top/categories/android/">android(25)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/caddy/">caddy(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/dart/">dart(5)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/docker/">docker(3)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/flutter/">flutter(60)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/github/">github(3)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/go/">go(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/golang/">golang(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/iOS/">iOS(6)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/ios/">ios(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/java/">java(6)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/jetbrains/">jetbrains(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/other/">other(3)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/python/">python(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/server/">server(5)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/spring/">spring(3)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/tools/">tools(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/%E6%9D%82%E9%A1%B9/">杂项(1)</a>
    </li>
    
    <li>
        <a href="http://www.kikt.top/categories/%E6%B6%82%E9%B8%A6/">涂鸦(1)</a>
    </li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title">标签</h3>
<div class="tagcloud">
    
    <a href="http://www.kikt.top/tags/10/">10</a>
    
    <a href="http://www.kikt.top/tags/2.3/">2.3</a>
    
    <a href="http://www.kikt.top/tags/Clipboard/">Clipboard</a>
    
    <a href="http://www.kikt.top/tags/Javassist/">Javassist</a>
    
    <a href="http://www.kikt.top/tags/Migrate/">Migrate</a>
    
    <a href="http://www.kikt.top/tags/aar/">aar</a>
    
    <a href="http://www.kikt.top/tags/actions/">actions</a>
    
    <a href="http://www.kikt.top/tags/aidl/">aidl</a>
    
    <a href="http://www.kikt.top/tags/android/">android</a>
    
    <a href="http://www.kikt.top/tags/androidQ/">androidQ</a>
    
    <a href="http://www.kikt.top/tags/androidX/">androidX</a>
    
    <a href="http://www.kikt.top/tags/apk/">apk</a>
    
    <a href="http://www.kikt.top/tags/app/">app</a>
    
    <a href="http://www.kikt.top/tags/appcode/">appcode</a>
    
    <a href="http://www.kikt.top/tags/azure/">azure</a>
    
    <a href="http://www.kikt.top/tags/ble/">ble</a>
    
    <a href="http://www.kikt.top/tags/bottomsheet/">bottomsheet</a>
    
    <a href="http://www.kikt.top/tags/butterknife/">butterknife</a>
    
    <a href="http://www.kikt.top/tags/c/">c</a>
    
    <a href="http://www.kikt.top/tags/caddy/">caddy</a>
    
    <a href="http://www.kikt.top/tags/camera/">camera</a>
    
    <a href="http://www.kikt.top/tags/cameraX/">cameraX</a>
    
    <a href="http://www.kikt.top/tags/channel/">channel</a>
    
    <a href="http://www.kikt.top/tags/cocoapods/">cocoapods</a>
    
    <a href="http://www.kikt.top/tags/cupertino/">cupertino</a>
    
    <a href="http://www.kikt.top/tags/dart/">dart</a>
    
    <a href="http://www.kikt.top/tags/dart-2.6/">dart-2.6</a>
    
    <a href="http://www.kikt.top/tags/desktop/">desktop</a>
    
    <a href="http://www.kikt.top/tags/dialog/">dialog</a>
    
    <a href="http://www.kikt.top/tags/dmg/">dmg</a>
    
    <a href="http://www.kikt.top/tags/doc/">doc</a>
    
    <a href="http://www.kikt.top/tags/docker/">docker</a>
    
    <a href="http://www.kikt.top/tags/docker-compose/">docker-compose</a>
    
    <a href="http://www.kikt.top/tags/excel/">excel</a>
    
    <a href="http://www.kikt.top/tags/exists/">exists</a>
    
    <a href="http://www.kikt.top/tags/faq/">faq</a>
    
    <a href="http://www.kikt.top/tags/fastlane/">fastlane</a>
    
    <a href="http://www.kikt.top/tags/ffi/">ffi</a>
    
    <a href="http://www.kikt.top/tags/ffmpeg/">ffmpeg</a>
    
    <a href="http://www.kikt.top/tags/flexmark/">flexmark</a>
    
    <a href="http://www.kikt.top/tags/flutter/">flutter</a>
    
    <a href="http://www.kikt.top/tags/flutter-web/">flutter-web</a>
    
    <a href="http://www.kikt.top/tags/focus/">focus</a>
    
    <a href="http://www.kikt.top/tags/focusNode/">focusNode</a>
    
    <a href="http://www.kikt.top/tags/form/">form</a>
    
    <a href="http://www.kikt.top/tags/framework/">framework</a>
    
    <a href="http://www.kikt.top/tags/github/">github</a>
    
    <a href="http://www.kikt.top/tags/go/">go</a>
    
    <a href="http://www.kikt.top/tags/golang/">golang</a>
    
    <a href="http://www.kikt.top/tags/gradle/">gradle</a>
    
    <a href="http://www.kikt.top/tags/http/">http</a>
    
    <a href="http://www.kikt.top/tags/iOS/">iOS</a>
    
    <a href="http://www.kikt.top/tags/ide/">ide</a>
    
    <a href="http://www.kikt.top/tags/idea/">idea</a>
    
    <a href="http://www.kikt.top/tags/index/">index</a>
    
    <a href="http://www.kikt.top/tags/inside/">inside</a>
    
    <a href="http://www.kikt.top/tags/ios/">ios</a>
    
    <a href="http://www.kikt.top/tags/java/">java</a>
    
    <a href="http://www.kikt.top/tags/jenkins/">jenkins</a>
    
    <a href="http://www.kikt.top/tags/jetbrains/">jetbrains</a>
    
    <a href="http://www.kikt.top/tags/jsdelivr/">jsdelivr</a>
    
    <a href="http://www.kikt.top/tags/json/">json</a>
    
    <a href="http://www.kikt.top/tags/json_serializable/">json_serializable</a>
    
    <a href="http://www.kikt.top/tags/junit/">junit</a>
    
    <a href="http://www.kikt.top/tags/library/">library</a>
    
    <a href="http://www.kikt.top/tags/live-template/">live-template</a>
    
    <a href="http://www.kikt.top/tags/loadmore/">loadmore</a>
    
    <a href="http://www.kikt.top/tags/log/">log</a>
    
    <a href="http://www.kikt.top/tags/mac/">mac</a>
    
    <a href="http://www.kikt.top/tags/macos/">macos</a>
    
    <a href="http://www.kikt.top/tags/maven/">maven</a>
    
    <a href="http://www.kikt.top/tags/mysql/">mysql</a>
    
    <a href="http://www.kikt.top/tags/navigationbar/">navigationbar</a>
    
    <a href="http://www.kikt.top/tags/navigator/">navigator</a>
    
    <a href="http://www.kikt.top/tags/ndk/">ndk</a>
    
    <a href="http://www.kikt.top/tags/nginx/">nginx</a>
    
    <a href="http://www.kikt.top/tags/oc/">oc</a>
    
    <a href="http://www.kikt.top/tags/opencv/">opencv</a>
    
    <a href="http://www.kikt.top/tags/poi/">poi</a>
    
    <a href="http://www.kikt.top/tags/pub/">pub</a>
    
    <a href="http://www.kikt.top/tags/python/">python</a>
    
    <a href="http://www.kikt.top/tags/retrofit/">retrofit</a>
    
    <a href="http://www.kikt.top/tags/route/">route</a>
    
    <a href="http://www.kikt.top/tags/server/">server</a>
    
    <a href="http://www.kikt.top/tags/so/">so</a>
    
    <a href="http://www.kikt.top/tags/spp/">spp</a>
    
    <a href="http://www.kikt.top/tags/sprintboot/">sprintboot</a>
    
    <a href="http://www.kikt.top/tags/swift/">swift</a>
    
    <a href="http://www.kikt.top/tags/tap/">tap</a>
    
    <a href="http://www.kikt.top/tags/thymeleaf/">thymeleaf</a>
    
    <a href="http://www.kikt.top/tags/tips/">tips</a>
    
    <a href="http://www.kikt.top/tags/toast/">toast</a>
    
    <a href="http://www.kikt.top/tags/transition/">transition</a>
    
    <a href="http://www.kikt.top/tags/ui/">ui</a>
    
    <a href="http://www.kikt.top/tags/utf8/">utf8</a>
    
    <a href="http://www.kikt.top/tags/yield/">yield</a>
    
    <a href="http://www.kikt.top/tags/%E4%BA%8C%E8%BF%9B%E5%88%B6/">二进制</a>
    
    <a href="http://www.kikt.top/tags/%E4%BA%A4%E5%8F%89/">交叉</a>
    
    <a href="http://www.kikt.top/tags/%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91/">交叉编译</a>
    
    <a href="http://www.kikt.top/tags/%E4%BB%8B%E7%BB%8D/">介绍</a>
    
    <a href="http://www.kikt.top/tags/%E4%BB%A3%E7%A0%81%E8%A7%84%E8%8C%83/">代码规范</a>
    
    <a href="http://www.kikt.top/tags/%E5%86%B2%E7%AA%81/">冲突</a>
    
    <a href="http://www.kikt.top/tags/%E5%8A%A8%E6%80%81/">动态</a>
    
    <a href="http://www.kikt.top/tags/%E5%8F%91%E5%B8%83/">发布</a>
    
    <a href="http://www.kikt.top/tags/%E5%8F%AF%E6%89%A7%E8%A1%8C/">可执行</a>
    
    <a href="http://www.kikt.top/tags/%E5%9B%BE%E5%BA%8A/">图床</a>
    
    <a href="http://www.kikt.top/tags/%E5%9F%8E%E5%B8%82/">城市</a>
    
    <a href="http://www.kikt.top/tags/%E5%A4%A7%E6%96%87%E4%BB%B6/">大文件</a>
    
    <a href="http://www.kikt.top/tags/%E5%B7%A5%E5%85%B7/">工具</a>
    
    <a href="http://www.kikt.top/tags/%E5%B7%B2%E6%9C%89%E9%A1%B9%E7%9B%AE/">已有项目</a>
    
    <a href="http://www.kikt.top/tags/%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/">开发环境</a>
    
    <a href="http://www.kikt.top/tags/%E6%80%BB%E7%BB%93/">总结</a>
    
    <a href="http://www.kikt.top/tags/%E6%85%A2/">慢</a>
    
    <a href="http://www.kikt.top/tags/%E6%89%93%E5%8C%85/">打包</a>
    
    <a href="http://www.kikt.top/tags/%E6%89%AB%E7%A0%81/">扫码</a>
    
    <a href="http://www.kikt.top/tags/%E6%8F%92%E4%BB%B6/">插件</a>
    
    <a href="http://www.kikt.top/tags/%E6%96%87%E6%A1%A3/">文档</a>
    
    <a href="http://www.kikt.top/tags/%E6%A8%A1%E6%9D%BF/">模板</a>
    
    <a href="http://www.kikt.top/tags/%E6%B8%B2%E6%9F%93/">渲染</a>
    
    <a href="http://www.kikt.top/tags/%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/">源码解析</a>
    
    <a href="http://www.kikt.top/tags/%E7%81%B0%E5%BA%A6/">灰度</a>
    
    <a href="http://www.kikt.top/tags/%E7%82%B9%E5%87%BB/">点击</a>
    
    <a href="http://www.kikt.top/tags/%E7%84%A6%E7%82%B9/">焦点</a>
    
    <a href="http://www.kikt.top/tags/%E7%88%AC%E8%99%AB/">爬虫</a>
    
    <a href="http://www.kikt.top/tags/%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86/">状态管理</a>
    
    <a href="http://www.kikt.top/tags/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE/">百度地图</a>
    
    <a href="http://www.kikt.top/tags/%E7%BC%96%E7%A0%81/">编码</a>
    
    <a href="http://www.kikt.top/tags/%E7%BC%96%E7%A8%8B%E6%8A%80%E5%B7%A7/">编程技巧</a>
    
    <a href="http://www.kikt.top/tags/%E7%BC%96%E8%AF%91/">编译</a>
    
    <a href="http://www.kikt.top/tags/%E7%BF%BB%E8%AF%91/">翻译</a>
    
    <a href="http://www.kikt.top/tags/%E8%93%9D%E7%89%99/">蓝牙</a>
    
    <a href="http://www.kikt.top/tags/%E8%A1%A8%E5%8D%95/">表单</a>
    
    <a href="http://www.kikt.top/tags/%E8%B7%AF%E7%94%B1/">路由</a>
    
    <a href="http://www.kikt.top/tags/%E8%BF%87%E5%9C%BA%E5%8A%A8%E7%94%BB/">过场动画</a>
    
    <a href="http://www.kikt.top/tags/%E9%9A%90%E7%A7%81/">隐私</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="https://github.com/Caijinglong" title="我的Github">我的Github</a>
        </li>
        
        <li>
            <a target="_blank" href="https://flutter.dev" title="flutter 官网">flutter 官网</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="http://www.kikt.top/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
        </div>
    </div>
</div>
<footer id="footer">
    <div class="container">
        <div>
            <p>如果我的blog对您有帮助,而您愿意捐赠 😆, 可以用下面的二维码</p>
            <img style="width:5rem;" src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&resolveLfs=true&%24format=octetStream&api-version=5.0&path=%2F20190424141834.png"/>
            <img style="width:5rem; padding-left: 2rem;" 
            src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&resolveLfs=true&%24format=octetStream&api-version=5.0&path=%2F20190424141931.png"/>
            <img style="width:5rem; padding-left: 2rem;" 
            src="https://dev.azure.com/cjlspy/844861b8-ee45-48a3-b430-b974684baaaa/_apis/git/repositories/bf4da1c1-1cfa-4f54-8a75-745cce2b737c/items?versionDescriptor%5Bversion%5D=master&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&resolveLfs=true&%24format=octetStream&api-version=5.0&path=%2F20190424142013.png"/>
        </div>
        &copy; 2018 <a href="http://www.kikt.top">caijinglong的博客 By caijinglong</a>.
        Powered by <a rel="nofollow noreferer noopener" href="https://gohugo.io" target="_blank">Hugo</a>.
        <a href="http://www.flysnow.org/" target="_blank">Theme</a> based on <a href="https://github.com/rujews/maupassant-hugo" target="_blank">maupassant</a>.<br/>
        本站所有内容基于<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" style="color:coral">CC4.0</a>协议发布,需要转载必须署名
        <br/>
        如果有问题可以<a href="mailto:cjl_spy@163.com">email联系我</a>
        <br/>
        京ICP备18038473号-1
        
    </div>
</footer>


    <script type="text/javascript" src="/js/prism.js" async="true"></script>
    <script type="text/javascript">
    
    (function(){
        $("pre code").parent().addClass("line-numbers")
    }())

    window.MathJax = {
        tex2jax: {
            inlineMath: [ ['$','$'] ],
            processEscapes: true
        }
    };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src="/js/totop.js?v=0.0.0" async=""></script>



<script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




</body>
</html>
